﻿<phone:PhoneApplicationPage xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"  
    x:Class="QWeiBoN.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:converter="clr-namespace:QWeiBoN.Converter"
    xmlns:imagetools="clr-namespace:ImageTools.Controls;assembly=ImageTools.Controls"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:es="clr-namespace:Microsoft.Expression.Shapes;assembly=Microsoft.Expression.Drawing"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded"
    BackKeyPress="PhoneApplicationPage_BackKeyPress">

    <phone:PhoneApplicationPage.Resources>

        <Style TargetType="RichTextBox">
            <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeNormal}" />
            <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}" />
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="BorderBrush" Value="Transparent" />
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="VerticalContentAlignment" Value="Center" />
            <Setter Property="Padding" Value="0" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="RichTextBox">
                        <Grid Background="Transparent">
                            <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Margin="{StaticResource PhoneHorizontalMargin}">
                                <ContentControl x:Name="ContentElement" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" Padding="{TemplateBinding Padding}"/>
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <imagetools:ImageConverter x:Key="ImageConverter" />

        <converter:StatusNameAndTextConverter x:Key="StatusNameAndTextConverter"/>
        <converter:StatusNameAndTextIsShow x:Key="StatusNameAndTextIsShow"/>
        <converter:TextImageSourceConverter x:Key="TextImageSourceConverter"/>
        <converter:StatusNameAndImageConverter x:Key="StatusNameAndImageConverter"/>
        <converter:ConvertWeiboContentBehavior x:Key="ConvertWeiboContentBehavior" />

        <shell:ApplicationBar x:Key="addNewBar" IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Resources/send.png" Text="发表" Click="ApplicationBarIconButton_Click" />
            <shell:ApplicationBarIconButton IconUri="/Resources/edit.png" Text="图片" Click="ApplicationBarIconButtonNewImg_Click" />
        </shell:ApplicationBar>
        <shell:ApplicationBar x:Key="addNewCommentBar" IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton IconUri="/Resources/send.png" Text="评论" Click="ApplicationBarIconButton_Click_2" />
            <shell:ApplicationBarIconButton IconUri="/Resources/edit.png" Text="返回" Click="ApplicationBarIconButton_Click_1" />
        </shell:ApplicationBar>
        <shell:ApplicationBar x:Key="mainActionBar" IsVisible="True" IsMenuEnabled="True" Opacity="0.9">
            <shell:ApplicationBarIconButton x:Name="ReloadBtn" IconUri="/Resources/icon/refresh.png" Text="刷新" Click="ReloadBtn_Click"/>
            <shell:ApplicationBarIconButton x:Name="AddStatusBtn" IconUri="/Resources/icon/edit.png" Text="添加" Click="AddStatusBtn_Click"/>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.Resources>

    <!--LayoutRoot 是包含所有页面内容的根网格-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <!--枢轴控件-->
        <controls:Pivot Title="我的微博" Name="MainPivot" SelectionChanged="MainPivot_SelectionChanged">
            <!--枢轴项一-->
            <controls:PivotItem Header="微博">
                <Grid>
                    <ListBox HorizontalAlignment="Left" Name="mainList" VerticalAlignment="Top" SelectionChanged="mainList_SelectionChanged" CacheMode="BitmapCache" LayoutUpdated="mainList_LayoutUpdated">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid Margin="0,10,0,0" VerticalAlignment="Top" Tag="{Binding Id}">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="60" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <!-- 行弹出菜单 -->
                                    <toolkit:ContextMenuService.ContextMenu>
                                        <toolkit:ContextMenu IsZoomEnabled="False" Style="{Binding ContextMenuStyle}">
                                            <toolkit:MenuItem Header="转播" Click="MenuItem_Replay" Tag="{Binding Id}" Style="{Binding MenuItemStyle}" />
                                            <toolkit:MenuItem Header="回复" Tag="{Binding Id}" Style="{Binding MenuItemStyle}" />
                                            <toolkit:MenuItem Header="收藏" Tag="{Binding Id}" Style="{Binding MenuItemStyle}" />
                                        </toolkit:ContextMenu>
                                    </toolkit:ContextMenuService.ContextMenu>
                                    <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
                                        <Image Name="UserHeader" Margin="0,5,0,0"  Stretch="None" Source="{Binding Head}"  HorizontalAlignment="Left" VerticalAlignment="Top" Tag="{Binding Name}" MouseLeftButtonDown="UserHeader_MouseLeftButtonDown" MouseLeftButtonUp="UserHeader_MouseLeftButtonUp" />
                                    </StackPanel>
                                    <StackPanel Grid.Column="1" Grid.Row="0" HorizontalAlignment="Left">
                                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top">
                                            <StackPanel Width="340" Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top">
                                                <!--
                                                <TextBlock TextWrapping="Wrap" Text="{Binding Nick}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0" />
                                                -->
                                                <HyperlinkButton Name="NickLinkButton" Content="{Binding Nick}" FontSize="21" Tag="{Binding Name}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0" Margin="-10,0,-10,0" Click="NickLinkButton_Click" />
                                                <TextBlock TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0" Text="{Binding Nexttime}" Margin="0,0,0,0" />
                                            </StackPanel>
                                            <HyperlinkButton Name="rePostLink" Content="转发" FontSize="18" Tag="{Binding Id}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,0" Click="rePostLink_Click" />
                                        </StackPanel>
                                        <RichTextBox Padding="0" FontSize="21" Margin="-10,5,0,0" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" Tag="{Binding Id}" CacheMode="BitmapCache">
                                            <i:Interaction.Behaviors>
                                                <converter:ConvertWeiboContentBehavior Content="{Binding Origtext}"></converter:ConvertWeiboContentBehavior>
                                            </i:Interaction.Behaviors>
                                        </RichTextBox>
                                        <!--
                                        <TextBlock TextWrapping="Wrap" Text="{Binding Origtext}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0" Margin="0,5,0,0"/>
                                        -->
                                        <Image Name="MyTextImg" Margin="0,5,0,0" Source="{Binding Image, Converter={StaticResource TextImageSourceConverter}}" Stretch="None" HorizontalAlignment="Left" VerticalAlignment="Top" MouseLeftButtonUp="MyTextImg_MouseLeftButtonUp" Tag="{Binding Image, Converter={StaticResource TextImageSourceConverter}}" MouseLeftButtonDown="MyTextImg_MouseLeftButtonDown" />
                                        <Grid Visibility="{Binding Source, Converter={StaticResource StatusNameAndTextIsShow}}" Margin="0,5,0,0">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="8" />
                                                <RowDefinition />
                                            </Grid.RowDefinitions>
                                            <es:RegularPolygon Style="{StaticResource ParentTextBackgroundArrow}">
                                                <es:RegularPolygon.RenderTransform>
                                                    <CompositeTransform SkewX="37"/>
                                                </es:RegularPolygon.RenderTransform>
                                            </es:RegularPolygon>
                                            <Grid Grid.Row="1" Style="{StaticResource TweetListParentTextBg}">
                                                <StackPanel Margin="5,5,0,10" HorizontalAlignment="Left" Orientation="Vertical">
                                                    <!--
                                            <TextBlock TextWrapping="Wrap"  VerticalAlignment="Top" Text="{Binding Source, Converter={StaticResource StatusNameAndTextConverter}}"/>
                                            -->
                                                    <HyperlinkButton Content="{Binding Source, Converter={StaticResource StatusNameAndTextConverter}}" FontSize="21" Tag="{Binding Source.OpenId}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0" Margin="-10,0,-10,0" Click="NickLinkButton_Click" />
                                                    <!--
                                            <TextBlock TextWrapping="Wrap"  VerticalAlignment="Top" Text="{Binding Source.Text}"/>
                                            -->
                                                    <RichTextBox Padding="0" FontSize="21" Margin="-10,5,0,0" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Top" CacheMode="BitmapCache">
                                                        <i:Interaction.Behaviors>
                                                            <converter:ConvertWeiboContentBehavior Content="{Binding Source.Origtext}"></converter:ConvertWeiboContentBehavior>
                                                        </i:Interaction.Behaviors>
                                                    </RichTextBox>
                                                    <Image Name="SourceImg" Margin="0,5,0,0" Source="{Binding Source, Converter={StaticResource StatusNameAndImageConverter}}" Tag="{Binding Source, Converter={StaticResource StatusNameAndImageConverter}}" Stretch="None" HorizontalAlignment="Left" VerticalAlignment="Top" MouseLeftButtonUp="SourceImg_MouseLeftButtonUp" MouseLeftButtonDown="SourceImg_MouseLeftButtonDown" />
                                                </StackPanel>
                                            </Grid>
                                        </Grid>
                                    </StackPanel>
                                    <StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Margin="0,10,10,10">
                                        <TextBlock TextWrapping="Wrap" FontSize="15"  VerticalAlignment="Top" Width="340" Text="{Binding From}"/>
                                    </StackPanel>
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                        <toolkit:GestureService.GestureListener>
                            <toolkit:GestureListener  GestureCompleted="GestureListener_GestureCompleted" GestureBegin="GestureListener_GestureBegin" DragStarted="GestureListener_DragStarted" />
                        </toolkit:GestureService.GestureListener>
                    </ListBox>
                    <Grid Name="CommentsPanel" Visibility="Collapsed">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="100" />
                        </Grid.RowDefinitions>
                        <ListBox HorizontalAlignment="Left" Name="CommentsList" VerticalAlignment="Top" ItemsSource="{Binding Singleline}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid Margin="0,10,0,0" VerticalAlignment="Top">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto" />
                                            <RowDefinition Height="Auto" />
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="60" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
                                            <Image Name="UserHeader" Margin="0,5,0,0"  Stretch="None" Source="{Binding Head}"  HorizontalAlignment="Left" VerticalAlignment="Top" Tag="{Binding Name}" />
                                        </StackPanel>
                                        <StackPanel Grid.Column="1" Grid.Row="0" HorizontalAlignment="Left">
                                            <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top">
                                                <TextBlock TextWrapping="Wrap" Text="{Binding Nick}" Width="340" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0" />
                                                <HyperlinkButton Name="rePostLink" Content="收听" FontSize="18" Tag="{Binding OpenId}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,0,0" />
                                            </StackPanel>
                                            <TextBlock TextWrapping="Wrap" Text="{Binding Origtext}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0" Margin="0,5,0,0"/>
                                        </StackPanel>
                                        <StackPanel Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" Margin="0,10,10,10">
                                            <TextBlock TextWrapping="Wrap" FontSize="15"  VerticalAlignment="Top" Width="340" Text="{Binding From}"/>
                                        </StackPanel>
                                    </Grid>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                        <Grid Grid.Row="1" Height="100">
                            <TextBox Margin="0,4,0,4" AcceptsReturn="True" Name="NewComment" VerticalAlignment="Top" Height="90"></TextBox>
                        </Grid>
                    </Grid>
                    <!-- 查看图片弹出Canvas -->
                    <Canvas x:Name="ShowImg" Visibility="Collapsed" Width="470" MinHeight="700" Background="LightGray" >
                        <Button x:Name="CloseCanvas" Width="70" Height="70" Margin="400,0,0,0" Content="X" Click="CloseCanvas_Click" />
                        <ScrollViewer VerticalScrollBarVisibility="Auto" Height="530" Margin="0,65,0,5">
                            <StackPanel Orientation="Vertical">
                                <Image Name="BigImgJpg" Visibility="Collapsed" Width="460" Margin="5,0,5,5" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Top" />
                                <imagetools:AnimatedImage Name="BigImg" Width="460" Margin="5,0,5,5" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Top" />
                            </StackPanel>
                        </ScrollViewer>
                    </Canvas>
                    <!-- 转发微博弹出Canvas -->
                    <Canvas x:Name="ShowRePostDiv" Visibility="Collapsed" Width="470" Height="610" HorizontalAlignment="Center" Background="LightGray">
                        <TextBox Margin="4,4,4,0" AcceptsReturn="True" Name="RePostContext" VerticalAlignment="Top" Height="180" Width="465" />
                        <StackPanel Orientation="Vertical" VerticalAlignment="Top">
                            <Image Name="RePostImgSource" MaxHeight="400" MaxWidth="300" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="90,180,10,0" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" Margin="0,520,0,0" HorizontalAlignment="Center" VerticalAlignment="Top">
                            <Button Name="RePostButton" Content="转 发" Click="RePostButton_Click" Margin="120,0,0,0" />
                            <!--<Button Name="RePostImgButton" Content="图 片" Margin="10,0,0,0" Click="RePostImgButton_Click" />-->
                            <Button Name="RePostCancelButton" Content="取 消" Margin="10,0,0,0" Click="RePostCancelButton_Click" />
                        </StackPanel>
                    </Canvas>
                    <!-- 微博点评列表 -->
                    <Canvas x:Name="WeiboComments" Visibility="Collapsed" Width="470" MinHeight="610" HorizontalAlignment="Left" Background="LightGray">
                        <Button x:Name="CloseCommentsCanvas" Width="70" Height="70" Margin="400,0,0,0" Content="X" />
                    </Canvas>
                </Grid>
            </controls:PivotItem>

            <!--枢轴项二-->
            <controls:PivotItem Header="收听">
                <Grid>
                    <ListBox HorizontalAlignment="Left" Name="fansList" VerticalAlignment="Top" ItemsSource="{Binding MyFans}" SelectionChanged="fansList_SelectionChanged">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <Grid Margin="0,10,0,0" VerticalAlignment="Top">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="60" />
                                        <ColumnDefinition Width="290" />
                                        <ColumnDefinition Width="160" />
                                    </Grid.ColumnDefinitions>
                                    <StackPanel HorizontalAlignment="Left" VerticalAlignment="Top">
                                        <Image Margin="0,5,0,0"  Stretch="None" Source="{Binding Head}"  HorizontalAlignment="Left" VerticalAlignment="Top" />
                                    </StackPanel>
                                    <StackPanel Grid.Column="1" Grid.Row="0" HorizontalAlignment="Left">
                                        <TextBlock TextWrapping="Wrap" Text="{Binding Nick}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0" />
                                        <TextBlock TextWrapping="Wrap" Text="{Binding Location}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0"
                                                   Margin="0,5,0,0"/>
                                    </StackPanel>
                                    <StackPanel Grid.Column="2" Grid.Row="0" HorizontalAlignment="Left">
                                        <Button Content="{Binding Email}" Tag="{Binding OpenId}" Height="Auto" Width="Auto" Click="Fans_Button_Click" Margin="0,0,10,0" />
                                    </StackPanel>
                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
                </Grid>
            </controls:PivotItem>
            
            <!--枢轴项三-->
            <controls:PivotItem Header="个人">
                <Grid>
                    <Image Name="UserImg" Height="160" HorizontalAlignment="Left" Margin="22,22,0,0" Stretch="Fill" VerticalAlignment="Top" Width="160" Source="{Binding User.Head}" />
                    <TextBlock FontSize="30" Margin="20,217,368,0" Text="听众" VerticalAlignment="Top" />
                    <TextBlock FontSize="30" Margin="102,217,239,0" Name="FansNum" VerticalAlignment="Top" Width="115" Text="{Binding User.Fansnum}" />
                    <TextBlock FontSize="30" Margin="20,260,370,0" Text="收听" VerticalAlignment="Top" />
                    <TextBlock FontSize="30" Margin="102,260,239,0" Name="IdolNum" Text="{Binding User.IdolNum}" VerticalAlignment="Top" Width="115" />
                    <TextBlock FontSize="30" Margin="20,303,368,0" Text="广播" VerticalAlignment="Top" />
                    <TextBlock FontSize="30" Margin="102,303,239,0" Name="Tweetnum" Text="{Binding User.Tweetnum}" VerticalAlignment="Top" Width="115" />
                    <TextBlock FontSize="30" HorizontalAlignment="Left" Margin="198,25,0,0" Name="UserName" Text="{Binding User.Nick}" VerticalAlignment="Top" Width="248" />
                </Grid>
            </controls:PivotItem>
            
            <!--枢轴项四-->
            <controls:PivotItem Header="发表">
                <Grid Name="AddGrid">
                    <TextBox Margin="4,4,4,0" AcceptsReturn="True" Name="NewContext" Text="{Binding Text}" VerticalAlignment="Top" Height="180" />
                    <Image MaxHeight="600" MaxWidth="400" HorizontalAlignment="Left" Source="{Binding ImageSource}" Stretch="Fill" VerticalAlignment="Top" Margin="18,190,10,018" />
                </Grid>
            </controls:PivotItem>
            
        </controls:Pivot>
    </Grid>

    <!--演示 ApplicationBar 用法的示例代码-->
    <!--<phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <shell:ApplicationBarIconButton x:Name="appbar_button1" IconUri="/Images/appbar_button1.png" Text="按钮 1"/>
            <shell:ApplicationBarIconButton x:Name="appbar_button2" IconUri="/Images/appbar_button2.png" Text="按钮 2"/>
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem x:Name="menuItem1" Text="菜单项 1"/>
                <shell:ApplicationBarMenuItem x:Name="menuItem2" Text="菜单项 2"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>-->
    
</phone:PhoneApplicationPage>